package com.chanyachting.emall.action.sale;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.chanyachting.emall.domain.Sellyacht;
import com.chanyachting.emall.form.SellyachtForm;
import com.chanyachting.emall.service.SellyachtService;
import com.chanyachting.emall.serviceImpl.SellyachtServiceImpl;

public class QuerySecondHandSaleAction  extends Action {
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		//一般页面记录数
		int COMMON_PAGE_SIZE = 20;
		//主页表示记录数
		int INDEX_PAGE_SIZE = 6;
		
		SellyachtService syService = new SellyachtServiceImpl();
		SellyachtForm sf = (SellyachtForm)form;
		
		int currentPage = sf.getCurrentPage();
		int pageSize;
		
		if ("1".equals(sf.getPageType())) {
			pageSize = COMMON_PAGE_SIZE;
		} else {
			pageSize = INDEX_PAGE_SIZE;
		}
		int pageCount = syService.QueryAppointSellYachtCount("01","89")/pageSize;
		if (syService.QueryAppointSellYachtCount("01","89")%pageSize > 0) {
			pageCount = pageCount + 1;
		}
		
		if (currentPage < 1) {
			currentPage = 1;
		} else if (currentPage > pageCount) {
			return mapping.findForward("error");
		}
		List<Sellyacht> sy = syService.QueryAppointSellYacht(currentPage, pageSize,"89");
		sf.setSyList(sy);
		sf.setPageCount(pageCount);
		
		return mapping.findForward("toAllSellyacht");
	}
}
